package scream.servlet;

import java.io.IOException;
//import java.io.PrintWriter;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;



import scream.excepcion.DAOExcepcion;
//import scream.negocio.SeguridadNegocio;
import scream.negocio.SeguridadNegocioTipoIntervencion;

/**
 * Servlet implementation class TipoIntervencionInsertarServlet
 */
@WebServlet("/TipoIntervencionInsertarServlet")
public class TipoIntervencionInsertarServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public TipoIntervencionInsertarServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		String x = request.getParameter("txtCodigoTipoIntervencion");
		String y = request.getParameter("txtNombreTipoIntervencion");
		
		
		SeguridadNegocioTipoIntervencion negocio = new SeguridadNegocioTipoIntervencion();
		
		if(x.equals("")){
			request.getRequestDispatcher("errorIngreso.jsp").forward(request, response);
			return;
		}
		if(y.equals("")){
			request.getRequestDispatcher("errorIngreso.jsp").forward(request, response);
			return;
		}
		
		
		try {
			negocio.insertarTipoIntervencion(x, y);
			//response.sendRedirect(request.getContextPath()
				//	+ "/TipoIntervencionInsertarServlet");
			
			//RequestDispatcher rd = request.getRequestDispatcher("/InsertarTipoIntervencion.jsp");
			//rd.forward(request, response) ;
			RequestDispatcher rd = request.getRequestDispatcher("exito_tipointervencion.jsp");
			rd.forward(request, response);
			
			
		} catch (DAOExcepcion e) {
			RequestDispatcher rd = request.getRequestDispatcher("error_tipointervencion.jsp");
			rd.forward(request, response);
		}

	}
		
		
		
}


